package com.example.zhu95.mytimber.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * @author zhu95 on 2017/11/30.
 */

public class LibraryViewPagerAdapter extends FragmentPagerAdapter {
    private Section[] sections;

    public LibraryViewPagerAdapter(FragmentManager fm, Section[] sections) {
        super(fm);
        this.sections = sections;
    }

    public Section[] getSections() {
        return sections;
    }

    @Override
    public int getCount() {
        return sections.length;
    }

    @Override
    public Fragment getItem(int position) {
        return sections[position].getFragment();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return sections[position].getTitle();
    }

    public static class Section {
        String title;
        Fragment fragment;

        public Section(String title, Fragment fragment) {
            this.title = title;
            this.fragment = fragment;
        }

        public String getTitle() {
            return title;
        }

        public Fragment getFragment() {
            return fragment;
        }
    }
}
